<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="90px">

      <el-form-item label="设备编号" prop="jdRegisterno">
        <el-input
          v-model="queryParams.jdRegisterno"
          placeholder="请输入设备编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="操作人姓名" prop="opeusername">
        <el-input
          v-model="queryParams.opeusername"
          placeholder="请输入操作人姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:WcsUsers:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:WcsUsers:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:WcsUsers:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:WcsUsers:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="WcsUsersList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="ID" align="center" prop="id" /> -->
      <el-table-column label="BCR编号" align="center" prop="bcrNo"  />
      <el-table-column label="设备编号" align="center" prop="jdRegisterno" min-width="140" :show-overflow-tooltip="true"/>
      <el-table-column label="签名" align="center" prop="jdSignature" min-width="200" :show-overflow-tooltip="true"/>
      <el-table-column label="分拣中心 id" align="center" prop="jdSitecode" min-width="140" :show-overflow-tooltip="true" />
      <el-table-column label="防篡改码" align="center" prop="jdAuthorization" min-width="200" :show-overflow-tooltip="true"/>
      <el-table-column label="操作码" align="center" prop="jdOpcode" min-width="200" :show-overflow-tooltip="true" />
      <el-table-column label="操作人 id" align="center" prop="opeuserid" min-width="140" :show-overflow-tooltip="true"/>
      <el-table-column label="操作人姓名" align="center" prop="opeusername" min-width="140" :show-overflow-tooltip="true"/>
      <el-table-column label="所属场地 id" align="center" prop="opesiteid" min-width="140" :show-overflow-tooltip="true"/>
      <el-table-column label="所属场地名称" align="center" prop="opesitename" min-width="140" :show-overflow-tooltip="true"/>
      <!-- <el-table-column label="备注" align="center" prop="comments"  /> -->
    <el-table-column label="创建时间" align="center" prop="createData" width="160">
        <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createData) }}</span>
        </template>
    </el-table-column>
      <!-- <el-table-column label="操作" align="center" min-width="140" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:WcsUsers:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:WcsUsers:remove']"
          >删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改称重分拣参数对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="BCR编号" prop="bcrNo">
          <el-input v-model="form.bcrNo" placeholder="请输入BCR编号" />
        </el-form-item>
        <el-form-item label="设备编号" prop="jdRegisterno">
          <el-input v-model="form.jdRegisterno" placeholder="请输入设备编号" />
        </el-form-item>
        <el-form-item label="签名" prop="jdSignature">
          <el-input v-model="form.jdSignature" placeholder="请输入签名" />
        </el-form-item>
        <el-form-item label="分拣中心 id" prop="jdSitecode">
          <el-input v-model="form.jdSitecode" placeholder="请输入分拣中心 id" />
        </el-form-item>
        <el-form-item label="防篡改码" prop="jdAuthorization">
          <el-input v-model="form.jdAuthorization" placeholder="请输入防篡改码" />
        </el-form-item>
        <el-form-item label="操作码" prop="jdOpcode">
          <el-input v-model="form.jdOpcode" placeholder="请输入操作码" />
        </el-form-item>
        <el-form-item label="操作人 id" prop="opeuserid">
          <el-input v-model="form.opeuserid" placeholder="请输入操作人 id" />
        </el-form-item>
        <el-form-item label="操作人姓名" prop="opeusername">
          <el-input v-model="form.opeusername" placeholder="请输入操作人姓名" />
        </el-form-item>
        <el-form-item label="所属场地 id" prop="opesiteid">
          <el-input v-model="form.opesiteid" placeholder="请输入所属场地 id" />
        </el-form-item>
        <el-form-item label="所属场地名称" prop="opesitename">
          <el-input v-model="form.opesitename" placeholder="请输入所属场地名称" />
        </el-form-item>
        <!-- <el-form-item label="备注" prop="comments">
          <el-input v-model="form.comments" placeholder="请输入备注" />
        </el-form-item> -->
        <!-- <el-form-item label="创建时间" prop="createData">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.createData"
            type="date"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择创建时间">
          </el-date-picker>
        </el-form-item> -->

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listWcsUsers, getWcsUsers, delWcsUsers, addWcsUsers, updateWcsUsers, exportWcsUsers } from "@/api/system/WcsUsers";

export default {
  name: "WcsUsers",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 称重分拣参数表格数据
      WcsUsersList: [],
        // 日期范围
        dateRange: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // ID字典
      idOptions: [],
      // BCR编号字典
      bcrNoOptions: [],
      // 设备编号字典
      jdRegisternoOptions: [],
      // 签名字典
      jdSignatureOptions: [],
      // 分拣中心 id字典
      jdSitecodeOptions: [],
      // 防篡改码字典
      jdAuthorizationOptions: [],
      // 操作码字典
      jdOpcodeOptions: [],
      // 操作人 id字典
      opeuseridOptions: [],
      // 操作人姓名字典
      opeusernameOptions: [],
      // 所属场地 id字典
      opesiteidOptions: [],
      // 所属场地名称字典
      opesitenameOptions: [],
      // 备注字典
      commentsOptions: [],
      // 创建时间字典
      createDataOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        bcrNo: null,
        jdRegisterno: null,
        jdSignature: null,
        jdSitecode: null,
        jdAuthorization: null,
        jdOpcode: null,
        opeuserid: null,
        opeusername: null,
        opesiteid: null,
        opesitename: null,
        comments: null,
        createData: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("${column.dictType}").then(response => {
      this.idOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.bcrNoOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.jdRegisternoOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.jdSignatureOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.jdSitecodeOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.jdAuthorizationOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.jdOpcodeOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.opeuseridOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.opeusernameOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.opesiteidOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.opesitenameOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.commentsOptions = response.data;
    });
    this.getDicts("${column.dictType}").then(response => {
      this.createDataOptions = response.data;
    });
  },
  methods: {
    /** 查询称重分拣参数列表 */
    getList() {
      this.loading = true;
              listWcsUsers(this.addDateRange(this.queryParams, this.dateRange)).then(
        response => {
        this.WcsUsersList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // ID字典翻译
    idFormat(row, column) {
      return this.selectDictLabel(this.idOptions, row.id);
    },
    // BCR编号字典翻译
    bcrNoFormat(row, column) {
      return this.selectDictLabel(this.bcrNoOptions, row.bcrNo);
    },
    // 设备编号字典翻译
    jdRegisternoFormat(row, column) {
      return this.selectDictLabel(this.jdRegisternoOptions, row.jdRegisterno);
    },
    // 签名字典翻译
    jdSignatureFormat(row, column) {
      return this.selectDictLabel(this.jdSignatureOptions, row.jdSignature);
    },
    // 分拣中心 id字典翻译
    jdSitecodeFormat(row, column) {
      return this.selectDictLabel(this.jdSitecodeOptions, row.jdSitecode);
    },
    // 防篡改码字典翻译
    jdAuthorizationFormat(row, column) {
      return this.selectDictLabel(this.jdAuthorizationOptions, row.jdAuthorization);
    },
    // 操作码字典翻译
    jdOpcodeFormat(row, column) {
      return this.selectDictLabel(this.jdOpcodeOptions, row.jdOpcode);
    },
    // 操作人 id字典翻译
    opeuseridFormat(row, column) {
      return this.selectDictLabel(this.opeuseridOptions, row.opeuserid);
    },
    // 操作人姓名字典翻译
    opeusernameFormat(row, column) {
      return this.selectDictLabel(this.opeusernameOptions, row.opeusername);
    },
    // 所属场地 id字典翻译
    opesiteidFormat(row, column) {
      return this.selectDictLabel(this.opesiteidOptions, row.opesiteid);
    },
    // 所属场地名称字典翻译
    opesitenameFormat(row, column) {
      return this.selectDictLabel(this.opesitenameOptions, row.opesitename);
    },
    // 备注字典翻译
    commentsFormat(row, column) {
      return this.selectDictLabel(this.commentsOptions, row.comments);
    },
    // 创建时间字典翻译
    createDataFormat(row, column) {
      return this.selectDictLabel(this.createDataOptions, row.createData);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        bcrNo: null,
        jdRegisterno: null,
        jdSignature: null,
        jdSitecode: null,
        jdAuthorization: null,
        jdOpcode: null,
        opeuserid: null,
        opeusername: null,
        opesiteid: null,
        opesitename: null,
        comments: null,
        createData: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加称重分拣参数";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getWcsUsers(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改称重分拣参数";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateWcsUsers(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addWcsUsers(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除称重分拣参数编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delWcsUsers(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有称重分拣参数数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportWcsUsers(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
